"""
    create by IAmFiveHigh on 2023/9/13
"""


def sum(arr: list[int]) -> int:
    return sum_by_recursion(arr, 0)


# 计算arr[l..<n]所有数的和
def sum_by_recursion(arr: list[int], l: int) -> int:
    if l == len(arr):
        return 0
    else:
        return arr[l] + sum_by_recursion(arr, l + 1)


if __name__ == '__main__':
    l1 = [1, 2, 3, 4, 5]
    print(f"{l1}.sum = {sum(l1)}")
